package tech.dongliang.system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tech.dongliang.system.model.SysUserRole;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xdzhang
 * @since 2019-01-18
 */
public interface SysUserRoleDao extends BaseMapper<SysUserRole> {
    @Select("SELECT roleId FROM sys_user_role WHERE userId=#{userId}")
    List<Integer> getUserRoleId(@Param("userId") Integer userId) throws Exception;

    @Delete("DELETE FROM sys_user_role WHERE userId = #{userId} ")
    int removeByUserId(@Param("userId") Integer userId) throws Exception;

    @Insert({
            "<script>",
            "insert into sys_user_role(roleId, userId) values ",
            "<foreach collection='roleIds' item='roleId' index='index' separator=','>",
            "(#{roleId}, #{userId})",
            "</foreach>",
            "</script>"
    })
    int insertRole(@Param("userId") Integer userId, @Param("roleIds") List<Integer> roleIds) throws Exception;
}
